package com.zp.utils;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

import java.util.concurrent.TimeUnit;

/**
 * Caffeine缓存工具类
 */
public class CaffeineUtil {
    private static final Cache<String, String> LOCAL_CACHE = Caffeine.newBuilder()
            .initialCapacity(1024) // 初始容量
            .maximumSize(10000L) // 最大容量
            .expireAfterWrite(5L, TimeUnit.SECONDS) // 5 分钟过期
            .build();

    public static Cache<String, String> getCache() {
        return LOCAL_CACHE;
    }
}
